<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="紧急程度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['emergencyDegree', validatorRules.emergencyDegree]" :trigger-change="true" dictCode="mes_urgent_cd" placeholder="请选择紧急程度"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="事项" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'items', validatorRules.items]" placeholder="请输入事项"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['result', validatorRules.result]" :trigger-change="true" dictCode="ba_yn" placeholder="请选择结果"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="角色" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'role', validatorRules.role]" placeholder="请输入角色"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'empname', validatorRules.empname]" placeholder="请输入人员"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="处理意见" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'handleResult', validatorRules.handleResult]" placeholder="请输入处理意见"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesPeChangeStatusModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDictSelectTag,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        remark: {},
        emergencyDegree: {rules: [{ required: true, message: '请输入紧急程度!' }]},
        items: {},
        result: {rules: [{ required: true, message: '请输入结果!' }]},
        role: {},
        empname: {},
        handleResult: {},
        },
        url: {
          add: '/mes-craft/auto/mesPeTrackListBasicinfo/addMesPeChangeStatus',
          edit: '/mes-craft/auto/mesPeTrackListBasicinfo/editMesPeChangeStatus',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','emergencyDegree','items','result','role','empname','handleResult','mesPeTrackListBasicinfoId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesPeTrackListBasicinfoId'] = this.mainId
                  this.formData['mesPeTrackListBasicinfoId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','emergencyDegree','items','result','role','empname','handleResult','mesPeTrackListBasicinfoId'))
      },


    }
  }
</script>
